package com.jrwd.recycletest.util;

/**
 * 相信自己，创造未来
 *
 * @author 小兵
 * @date 2017/10/21
 * 拼接提交服务端数据
 */

public class PostParamsBuilder {

    private StringBuilder sb = new StringBuilder("{");

    /**
     * 拼接参数
     * @param key
     * @param value
     * @return
     */
    public PostParamsBuilder setParams(String key, String value){
        sb.append("\"").append(key).append("\":\"").append(value).append("\",");
        return this;
    }

    public PostParamsBuilder setParam(String key, String value){
        sb.append("\"").append(key).append("\":").append(value).append(",");
        return this;
    }

    public PostParamsBuilder setParams(String key, int value){
        sb.append("\"").append(key).append("\":\"").append(value).append("\",");
        return this;
    }

    public PostParamsBuilder setParam(String key, int value){
        sb.append("\"").append(key).append("\":").append(value).append(",");
        return this;
    }

    /**
     * 返回最终的拼接 字段
     * @return
     */
    public String build(){
        String str = sb.toString();
        if(str.endsWith(",")){
            str = str.substring(0,str.length()-1)+"}";
        }else{
            str = str+"}";
        }
        QTLog.e("yxb---json--"+str);
        try{
            str = new AesCrypt().encrypt(str);
        }catch (Exception e){
            e.printStackTrace();
        }

        return str;
    }

}
